package com.eastseeway.radioproject.config;


import static androidx.core.content.ContextCompat.startActivity;

import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.util.Log;
import android.widget.Toast;

import androidx.lifecycle.Observer;

import com.eastseeway.radioproject.R;
import com.eastseeway.radioproject.RadioApplication;
import com.eastseeway.radioproject.base.BaseActivity;
import com.eastseeway.radioproject.databinding.ActivityConfigBinding;
import com.eastseeway.radioproject.entities.MessageEvent;
import com.eastseeway.radioproject.entities.UserInfo;
import com.eastseeway.radioproject.utils.SPHelper;
import com.google.gson.Gson;

import org.greenrobot.eventbus.Subscribe;
import org.greenrobot.eventbus.ThreadMode;

public class ConfigActivity extends BaseActivity<ActivityConfigBinding,ConfigViewModel> {

    private UserInfo mAdminInfo;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_config;
    }

    @Override
    protected Class<ConfigViewModel> getVMClass() {
        return ConfigViewModel.class;
    }

    @Override
    protected void initEvent() {
        super.initEvent();
        mBinding.setMViewModel(mViewModel);
        mBinding.back.setOnClickListener(v -> finish());
        mBinding.goToSetting.setOnClickListener(v->{
                Intent intent = new Intent(Settings.ACTION_SETTINGS);
                startActivity(intent);
        });

        int pressureOffset = SPHelper.getPressureOffset(this);
        mViewModel.getPressureOffset().setValue(pressureOffset);

    }

    @Override
    protected void loadData() {
        super.loadData();
        //      初始化仪器类型
        String machineType = getMachineType(this);
        mViewModel.getMachineType().setValue(machineType);

//        初始化音量
        int volume = RadioApplication.getInstance().getJwsManager().jwsGetVolume();
        mViewModel.getProgress().setValue(volume);

//        初始化仪器编号
        String deviceId = SPHelper.getDeviceId(this);
        mViewModel.getDeviceId().setValue(deviceId);

    }

    @Override
    protected void observeData() {
        super.observeData();
        mViewModel.getProgress().observe(this,volume-> {
            playClickSound();
            RadioApplication.getInstance().getJwsManager().jwsSetVolume(volume);
        });

    }

    @Subscribe(threadMode = ThreadMode.MAIN)
    public void OnEvent(MessageEvent messageEvent){

    }
}
